{% extends 'template.html' %}
{% load staticfiles %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">地区信息</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a>
                                <button type="button" class="btn btn-success" onclick="add_area()">新增地区
                                </button>
                            </a>
                            <a>
                                <button id='bt-del' data-text="确定删除接口? 0个" type="button"
                                        class="btn btn-danger">删除
                                </button>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        {% if all_area %}
                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th class="center sorting_disabled">
                                        <label class="pos-rel">
                                            <input id='chb-all' type="checkbox"/>
                                        </label>
                                    </th>
                                    <th style="display: none;">id</th>
                                    <th>中文名</th>
                                    <th>缩写</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for area in all_area %}
                                    <tr>
                                        <td class=" dt-body-center"><input type="checkbox"></td>
                                        <td style="display: none;" id="{{ area.id }}"
                                            value="{{ area.id }}"
                                            name="{{ area.id }}">{{ area.id }}</td>
                                        <td>{{ area.chinese_name }}</td>
                                        <td>{% if area.short_name %}{{ area.short_name }}{% endif %}</td>
                                        <td>
                                            <button class="btn btn-primary" onclick="edit_area({{ area.id }})">
                                                修改
                                            </button>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p>还没有地区信息，请先添加！</p>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- Edit Modal-->
            <div class="modal fade" id="Modal-edit" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">修改地区信息</h4>
                        </div>
                        <form>
                            <div class="modal-body">
                                <input style="display: none" id="edit_area_id">
                                <div class="alert alert-danger alert-dismissable" id='modal-notify-edit-area'>
                                    <button type="button" class="close" id="bt-modal-notify-edit-api">&times;</button>
                                    <label id='lb-msg-edit-api'></label>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">中文名</label>
                                    <div class="col-md-8">
                                        <input name="edit_chinese_name" id="edit_chinese_name" value="" class="form-control"
                                               placeholder="请输入中文名">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">简称</label>
                                    <div class="col-md-8">
                                        <input name="edit_short_name" id="edit_short_name" value="" class="form-control"
                                               placeholder="请输入简称">
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary" name='action'
                                        onclick="save_edit_area()">保存
                                </button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <!-- Add API INFO Modal-->
            <div class="modal fade" id="Modal-Add" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">新增地区信息</h4>
                        </div>
                        <form>
                            <div class="modal-body">
                                <div class="alert alert-danger alert-dismissable" id='modal-notify-add-area'>
                                    <button type="button" class="close" id="bt-modal-notify-add-api">&times;</button>
                                    <label id='lb-msg-add-api'></label>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">中文名</label>
                                    <div class="col-md-8">
                                        <input name="chinese_name" id="chinese_name" value="" class="form-control"
                                               placeholder="请输入中文名">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">简称</label>
                                    <div class="col-md-8">
                                        <input name="short_name" id="short_name" value="" class="form-control"
                                               placeholder="请输入简称">
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary" onclick="save_add_area()"
                                        name='action'>新增
                                </button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <div id="is_superuser" data-is-superuser="{{ is_superuser }}"></div>

        </div>
    </div>
{% endblock %}
{% block bodyjs %}
    <script src="/static/js/select2.min.js"></script>
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
    <script src="/static/js/area.js?v=sdf9htnjf123dgddgdnsfnsjtgng0sf"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
{% endblock %}
